<?php
    session_start();
	require_once 'config.php' ;

	function getPassword($user, $pw) {
        global $DB, $table_prefix;
        $passwd = $DB->GetOne("SELECT `user_pass` from `${table_prefix}user` where `user_name` = ?", array($user));
        return $passwd;
    }

    function getIdForUser($user) {
        global $DB, $table_prefix;
        $passwd = $DB->GetOne("SELECT `user_id` from `${table_prefix}user` where `user_name` = ?", array($user));
        return $passwd;
    }

    if(isset($_POST['submit'])) {
       $pass=getPassword($_POST['username'],$_POST['password']);

       if($pass== md5($_POST['password']))
     {
         $_SESSION['logged'] = true;
         $_SESSION['username'] = $_POST['username'];
         $_SESSION["userid"] =
         header('Location: table.php');
        exit;
       }
   else
   {
         header('Location: Login.html');
   }
}
?>
<html>
<head>
<title>Forgot Password</title>
  <link href="css/main.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" >

    function getQ()
    {
    var xmlHttp;
    var username = document.frmLogin.username.value;
	xmlHttp = new XMLHttpRequest();

	xmlHttp.onreadystatechange  = function()
	{
		if(xmlHttp.readyState == 4) {

			var resultHolder = document.getElementById("checkresult");
			if(xmlHttp.responseText == "unavailable") {
				resultHolder.innerHTML = "<font color=\"red\">User verified</font>";
			}
			else {
				resultHolder.innerHTML = "<font color=\"green\">Userame can not be verified!</font>";
			}
    	}
    }

	xmlHttp.open("GET","checkuser.php?username="+username,true);
    xmlHttp.send(null);


	}
    </script>

</head>
<body>
<form action="forgot.php" name="frmLogin" method="post">
<br/><br/><br/>
<table cellspacing="2" cellpadding="3" align="center" class="menu_table">
    <tr>
        <td><b>Username:</td><td><input type='text' name='username'>&nbsp;<span id="checkresult"></span></td>
        <td><a href="javascript:getQ();">Verify me!</a></td>
     </tr>
    <tr>
        <td><b>Secret Question:</b></td>
        </tr>
    <tr>
        <td><b>Secret Answer:</b></td><td> <input type='text' name='secans'></td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: center;"><input type="submit" value='Change Password' name='submit'></td>
    </tr>
</table>
</form>
</body>
</html>


